<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        thead {
            background-color: skyblue;
            /* display: block; */
            /* padding: 10px; */
            height: 60px;
            width: 400px;
            /* overflow: hidden; */
        }
        
        .title th {
            width: 50px;
            /* padding-right: 10px; */
            /* float: left; */
        }
        
        .list>td {
            width: 50px;
        }
        
        #box {
            padding: 50px;
            border: 1px seagreen solid;
        }
    </style>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <div id="box">
        <div>搜索名称：<input type="text" v-model="msg" @input="search"></div>
        <table style="border-collapse: collapse;">
            <thead class="title">
                <th v-for="(val,key) in arr[0]">{{key|toUp}}</th>

            </thead>
            <tr v-for="(item,index) in search" :key="index" class="list">
                <td>{{item.name}}</td>
                <td>{{item.gender}}</td>
                <td>{{item.age}}</td>

            </tr>

            <!-- <th v-for="(item,index) in newarr">
                {{item.name}}
            </th>
            <th v-for="(item,index) in newarr">
                {{item.gender}}
            </th>
            <th v-for="(item,index) in newarr">
                {{item.age}}
            </th> -->
        </table>
    </div>

    <script>
        let vm = new Vue({
            el: "#box",
            data: {
                msg: "",
                arr: [{
                    name: 'rick',
                    gender: 'male',
                    age: 21
                }, {
                    name: 'demen',
                    gender: 'male',
                    age: 26
                }, {
                    name: 'Jack',
                    gender: 'male',
                    age: 26
                }, {
                    name: 'John',
                    gender: 'female',
                    age: 20
                }, {
                    name: 'Lucy',
                    gender: 'female',
                    age: 16
                }, ],
                newarr: []
            },
            filters: {
                toUp(val) {
                    return val.charAt(0).toUpperCase() + val.substr(1)
                }
            },
            computed: {
                search() {
                    this.newarr = []
                    for (var i in this.arr) {
                        //    var str = ''
                        //    str.toLowerCase
                        var str = this.arr[i].name.toLowerCase()
                        var newmsg = this.msg.toLowerCase()
                        if (str.match(newmsg) != null) {
                            this.newarr.push(this.arr[i])
                        }
                    }
                    console.log(this.newarr);
                    return this.newarr
                }
            },
        })
    </script>
</body>

</html>